
// import vueFilePreview from 'gxd-file-preview';

const util = require("../../../common/js/util");
var app = getApp();
import Qs from "qs";

Page({
  data: {
    items: [
      { name: 'angular', value: 'AngularJS' },
      { name: 'react', value: 'React', checked: true },
      { name: 'polymer', value: 'Polymer' },
      { name: 'vue', value: 'Vue.js' },
      { name: 'ember', value: 'Ember.js' },
      { name: 'backbone', value: 'Backbone.js', disabled: true },
    ],
    datalist:[
      {
        PERSONNEL_ID:"1",
        PERSONNEL_NAME:"张三",
      },
      {
        PERSONNEL_ID:"2",
        PERSONNEL_NAME:"李四",
      }
    ],
    showWeb1: false,
    nameLoading:false,
    searchList: {
      fileList: [
        {
          FILE_NAME: "OOOJKKK.doc",
          FILE_TYPE: ".doc",
          icon: "/static/img/office-word.png",
          url: "http://test.yuehong.pro/YhERP/uploadFiles/uploadImgs/20220426/6d8c1c47ef934c60b161ac7f294c0aa1.doc?y=123"
          //url:"http://test.yuehong.pro/YhERP/uploadFiles/uploadImgs/20220426/0164ea3d43794a44a3972ab492fa30db.docx?s=123"
        },
        {
          FILE_NAME: "岳鸿纪录片解说词V3 20220325",
          FILE_TYPE: ".docx",
          icon: "/static/img/office-word.png",
          PATH: "http://file1.yuehong.pro/FileUpload/2022/08_1dlb0lc1lxfbxb8x88o6l0xxnl341d0136e4l6xc0xo19d06c4o4c4996xf80o94/1078f4b8fa1942c1bead2f797da278b0.docx"

        },
        {

          icon: "/static/img/office-word.png",
          FILE_NAME: "test",
          FILE_TYPE: ".doc",
          PATH: "http://file1.yuehong.pro/FileUpload/2022/08_1dlb0lc1lxfbxb8x88o6l0xxnl341d0136e4l6xc0xo19d06c4o4c4996xf80o94/83305f7d0e2142f7b61015b069701a96.doc"

        },
        {
          FILE_NAME: "岳鸿纪录片解说词V3 20220325.docx",
          FILE_TYPE: ".docx",
          icon: "/static/img/office-word.png",
          PATH: "http://file1.yuehong.pro/TestFileUpload/2022/08_1dlb0lc1lxfbxb8x88o6l0xxnl341d0136e4l6xc0xo19d06c4o4c4996xf80o94/d5935ea6e20447008fff1b712b02e6ac.docx"
        },
        {
          FILE_NAME: "无锁并发框架-Disruptor.pdf",
          FILE_TYPE: ".pdf",
          icon: "/static/img/office-pdf.png",
          url: "http://test.yuehong.pro/YhERP/uploadFiles/uploadImgs/20220423/60cead4c4f07439b90bac774bcb4f4ef.pdf"
        },
        {
          FILE_NAME: "20220119143101.xls",
          icon: "/static/img/office-excel.png",
          FILE_TYPE: ".xls",
          url: "http://test.yuehong.pro/YhERP/uploadFiles/uploadImgs/20220423/dc174770072b43f1b9477ed20519c6b5.xls"
        }
      ]
    }
  },
  onLoad(e) {
    // console.log(app.prototype.$Token );

    // this.webViewContext = dd.createWebViewContext('web-view-1');
    // console.log(this.webViewContext);
    app.getUserNameMapFn({}, app);
  },
  onReady() {

    // this.select_category_list.openFn({PROJECT_ID:""});

  },
  clickFn(){
    console.log("--消息提示");
    dd.showToast({
      content: "这是一个消息提示",
      fail: er => {
        console.log("---er",er);
      },
    });
  },
  operatorData() {
    let searchList = this.searchList;
    for (let index = 0; index < searchList.fileList.length; index++) {
      const element = searchList.fileList[index];
      element.web_view = false;
      element.is_web_view = 0;
      switch (element.type) {
        case "pdf":
          element.icon = "/static/img/office-pdf.png";
          element.is_web_view = 1;
          break;
        case "doc", "docx":
          element.icon = "/static/img/office-word.png";
          element.is_web_view = 1;
          break;
        case "xls", "xlsx":
          element.icon = "/static/img/office-excel.png";
          element.is_web_view = 1;
          break;
        default:
          element.icon = element.url;
          break;
      }
    }
    this.setData({
      searchList
    })
  },
  img_fileList(ref) {
    this.img_fileList = ref
  },
  onSubmit(e) {
    my.alert({
      content: e.detail.value.lib,
    });
    console.log('onSubmit', e.detail);
  },
  onReset(e) {
    console.log('onReset', e);
  },
  radioChange(e) {
    console.log('你选择的框架是：', e.detail.value);
  },
  onmessage(e) {
    console.log(e);

  },
  select_category_list(ref) {
    this.select_category_list = ref;
  },
  // 钉盘 预览
  imgClick_dingpang(e) {
    let index = e.currentTarget.dataset.index;
    let data = this.data.searchList.fileList[index];
    let url = data.url;
    let type = data.FILE_TYPE;
    let name = data.FILE_NAME;

    //   dd.saveFileToDingTalk({
    //     url,  // 文件在第三方服务器地址
    //     name,
    //     success: (res) => {
    //       console.log("--文件名称:",name);
    //       console.log(res);
    //     },
    //     fail: (err) =>{
    //         dd.alert({
    //             content:JSON.stringify(err)
    //         })
    //     }
    // })
    //   dd.chooseDingTalkDir({
    //     success: (res) => {
    //       console.log("---选择目录:",res);
    //         /* data结构
    //          {"data":
    //             [
    //                 {
    //                     "spaceId": "" //被选中的空间id
    //                     "path": "", // 被选中的文件夹路径
    //                     "dirId": "", //被选中的文件夹id
    //                 }
    //             ]
    //          }
    //        */
    //     },
    //     fail: (err) =>{
    //         dd.alert({
    //             content:JSON.stringify(err)
    //         })
    //     }
    // })

    dd.uploadAttachmentToDingTalk({
      types: ["space"],
      success: (res) => {
        console.log("---res", res);
      }
    })
  },
  // h5预览
  imgClick(e) {
    // let url = e.currentTarget.dataset.url;
    // let type = e.currentTarget.dataset.type;
    // let name = e.currentTarget.dataset.name;
    let index = e.currentTarget.dataset.index;
    let data = this.data.searchList.fileList[index];
    let url = data.url;
    let type = data.type;
    let name = data.name;
    // console.log(url, type);

    // this.setData({
    //   [`searchList.fileList[${index}].web_view`]:true,
    //   showWeb1:true
    // })
    data.patch = "/pages/radio/radio/radio";
    
    // let json={
    //   url:data.url?data.url:data.PATH,
    //   FILE_TYPE:data.FILE_TYPE
    // }
    console.log("--radio",data);
    let p = Qs.stringify(data);
    let path = '/pages/web_view/file_view/file_view';
    // console.log(p);

    let to_url = `${path}?${p}`;
    //debugger
    dd.navigateTo({
      url: to_url
    })


    // dd.downloadFile({
    //   url,
    //   success({ filePath }) {
    //     console.log(filePath);
    //     dd.alert({
    //       content:filePath,
    //     });
    //     // dd.previewImage({
    //     //   urls: [filePath],
    //     // });
    //   },
    //   fail(res) {
    //     dd.alert({
    //       content: res.errorMessage || res.error,
    //     });
    //   },
    // });

    // this.webViewContext = dd.createWebViewContext(`web-view-${index}`);

    //console.log(this.data.searchList.fileList);

    // data.corpId=dd.corpId;
    // dd.previewFileInDingTalk(data);
    // let data = {
    //   corpId: "ding8bf37c46f1e3cd1ebc961a6cb783455b",
    //   fileId: "57674039134",
    //   fileName: "无锁并发框架-Disruptor.pdf",
    //   fileSize: 972055,
    //   fileType: "pdf",
    //   spaceId: "43263416",
    // }
    // dd.previewFileInDingTalk(data);
    // try {
    //   let file_obj = {};
    //   let obj = dd.getStorageSync({ key: "file_list" });
    //   if (util.isNotEmpty(obj)) {
    //     if (util.isNotEmpty(obj[name])) {
    //       file_obj = obj[name];
    //     }
    //   }
    //   if (util.isNotEmpty(file_obj)) {
    //     dd.previewFileInDingTalk(data)
    //   } else {
    //     dd.saveFileToDingTalk({
    //       url,  // 文件在第三方服务器地址
    //       name,
    //       success: (res) => {
    //         //  console.log(res.data[0]);
    //         let data = res.data[0];
    //         data.corpId = dd.corpId;
    //         data.unionId = app.prototype.unionId;
    //         obj[name] = data
    //         // console.log(data);
    //         dd.previewFileInDingTalk(data);
    //         dd.setStorageSync({ key: "file_list", data });
    //       },
    //       fail: (err) => {
    //         dd.alert({
    //           content: JSON.stringify(err)
    //         })
    //       }
    //     })
    //   }
    // } catch (e) {
    //   console.log(e);
    // }
  },
  selectitem(e){

    console.log("---selectitem:",e);
  },
  nameInput(e){
    let datalist=this.data.datalist;
    let json={
      PERSONNEL_ID:"2",
      PERSONNEL_NAME:"WN+"+e,
    }
    datalist.push(json);
    this.setData({
      nameLoading:true
    })
    this.setData({
      datalist
    })
    setTimeout(()=>{
      this.setData({
        nameLoading:false
      })
    },1000)
   // console.log("---nameInput:",e);
  }
});
